package org.snail.exception;

import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {
    private static final Logger logger =  Logger.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(GroupException.class)
    @ResponseBody
    public JsonResult groupExp(BaseException exp){
        JsonResult result = new JsonResult(exp);
        result.setCode(exp.getErrCode());
        result.setMessage(exp.getMessage());
        return result;
    }

    @ExceptionHandler(EmpException.class)
    @ResponseBody
    public JsonResult empException(EmpException exp){
        JsonResult result = new JsonResult(exp);
        result.setCode(exp.getErrCode());
        result.setMessage(exp.getMessage());
        return result;
    }
    @ExceptionHandler(CommonException.class)
    @ResponseBody
    public JsonResult commonException(BaseException exp){
        JsonResult result = new JsonResult(exp);
        result.setCode(exp.getErrCode());
        result.setMessage(exp.getMessage());
        return result;
    }

    @ExceptionHandler(APIException.class)
    @ResponseBody
    public JsonResult apiException(BaseException exp){
        JsonResult result = new JsonResult(exp);
        result.setCode(exp.getErrCode());
        result.setMessage(exp.getMessage());
        return result;
    }

    @ExceptionHandler(SqlException.class)
    @ResponseBody
    public JsonResult sqlException(BaseException exp){
        JsonResult result = new JsonResult(exp);
        result.setCode(exp.getErrCode());
        result.setMessage(exp.getMessage());
        return result;
    }


}